/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AccesoEJB;

import Beans.LogicaRemote;
import VOs.City;
import VOs.Country;
import VOs.Enterprise;
import VOs.Location;
import VOs.Plan;
import VOs.Reserve;
import VOs.Users;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Julian
 */
@EJB(name = "Logica", beanInterface = LogicaRemote.class)
public class EJBLogica {

    static public LogicaRemote StartContext() throws NamingException {
        InitialContext ctx = new InitialContext();
        LogicaRemote a = (LogicaRemote) ctx.lookup("java:comp/env/Logica");
        return a;

    }

    public boolean checklogin(String username, String pass) throws Exception{
    return StartContext().checklogin(username, pass);
    }

    public boolean checkAdminLogin(String username, String pass) throws NamingException{
    return StartContext().checkAdminLogin(username, pass);
    }

    public boolean createUsers(String username, String name, String lastname, String phone, String pass, String creditcard, String email,String identification) throws Exception{
    return StartContext().createUsers(username, name, lastname, phone, pass, creditcard, email,identification);
    }

    public boolean editUsers(String username, String name, String lastname, String phone, String pass, String creditcard, String email) throws Exception{
    return StartContext().editUsers(username, name, lastname, phone, pass, creditcard, email);
    }

    public List<City> findCitybyCountry(String Country) throws Exception{
    return StartContext().findbyCountry(Country);
    }

    public List<Country> findallCountries() throws Exception{
    return StartContext().findallCountries();
    }

    public boolean createReserve(int idplan, int idslocation, Date inicio, Date fin, String idext) throws Exception{
    return StartContext().createReserve(idplan, idslocation, inicio, fin, idext);
    }

    public boolean editReserve(int idplan, int idslocation, Date inicio, Date fin, String idext) throws Exception{
    return StartContext().editReserve(idplan, idslocation, inicio, fin, idext);
    }


    public List<Reserve> findReserveByPlan(int id) throws Exception{
    return StartContext().findByPlan(id);
    }

    public boolean createLocation(String Address, int City, String Enterprise) throws Exception{
    return StartContext().createLocation(Address, City, Enterprise);
    }

    public boolean editLocation(int ID, String Address, int City) throws Exception{
    return StartContext().editLocation(ID, Address, City);
    }


    public List<Location> getLocation(String Enterprise) throws Exception{
    return StartContext().getLocation(Enterprise);

    }

    public int TotalReserveByPlan(int id) throws Exception{
    return StartContext().TotalByPlan(id);
    }

    boolean editEnterprise(String idEnterprise, String newUrl, String newPhone, String newIdType) throws NamingException{
    return StartContext().editEnterprise(idEnterprise, newUrl, newPhone, newIdType);
    }

    public Enterprise getEnterpriseById(String referenceId) throws Exception{
    return StartContext().getEnterpriseById(referenceId);
    }

    public List<Enterprise> getEnterpriseByType(String referenceIdType, int codePage, int pageLength) throws Exception{
    return StartContext().getEnterpriseByType(referenceIdType, codePage, pageLength);
    }

    boolean createPlan(String userName) throws NamingException{
    return StartContext().createPlan(userName);
    }

    public List<Plan> getPlanByUsername(String userName, int pageCode, int pageLength) throws NamingException{
    return StartContext().getPlanByUsername(userName, pageCode, pageLength);
    }
    public List<Plan> getPlanOnlyByUsername(String userName) throws Exception{
        return StartContext().getPlansWithActiveReservesByUsername(userName);
    }

    public boolean cancelReserve(int idreserva) throws Exception{
    return StartContext().cancelReserve(idreserva);
    }

    public List<Location> getLocationCity (int idCity) throws Exception{
    return StartContext().getLocationCity(idCity);
    }
    public List<Location> getLocationByTipeEnterprise (String idTipe) throws Exception{
    return StartContext().getLocationByTipeEnterprise(idTipe);
    }

    public List<City> findallCity() throws Exception {
    return StartContext().findallCity();
    }

    public Users getUser(String username) throws Exception{
    return StartContext().User(username);
    }
    public static Plan createPlan2(String userName) throws NamingException{
    return StartContext().createPlan2(userName);
    }
    public List<Plan> getallPlanbyUser(String user) throws Exception {
    return StartContext().getall(user);
    }
}
